package com.jinmdz.fmis.dao.admin.dao;

import com.jinmdz.fmis.dao.admin.dao.provider.SystemMenuProvider;
import com.jinmdz.fmis.dao.admin.model.systemmenu.SystemMenuEditItem;
import com.jinmdz.fmis.dao.admin.model.systemmenu.SystemMenuListItem;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultType;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;

import java.util.ArrayList;

/**
 * 系统菜单Dao
 *
 * @author LiCongLu
 * @date 2020-03-18 15:24
 */
public interface SystemMenuDao {

    /**
     * 查询系统菜单列表
     *
     * @param businessSystemId 业务系统主键
     * @return
     * @author LiCongLu
     * @date 2020-03-18 15:29
     */
    @SelectProvider(type = SystemMenuProvider.class, method = "listSystemMenuListByBusinessSystemId")
    ArrayList<SystemMenuListItem> listSystemMenuListByBusinessSystemId(@Param("businessSystemId") Integer businessSystemId);

    /**
     * 按照主键获取系统菜单信息
     *
     * @param id 主键
     * @return
     * @author LiCongLu
     * @date 2020-03-18 15:29
     */
    @SelectProvider(type = SystemMenuProvider.class, method = "getSystemMenuEditById")
    SystemMenuEditItem getSystemMenuEditById(@Param("id") Integer id);

    /**
     * 按照父主键获取菜单个数
     *
     * @param parentId 父主键
     * @return
     * @author LiCongLu
     * @date 2020-03-16 11:06
     */
    @Select(" select count(*) as menu_count from business_system_menu where parent_id = #{parentId} and deleted = 0 ")
    @ResultType(Integer.class)
    Integer getMenuCountByParentId(@Param("parentId") Integer parentId);

    /**
     * 按照菜单名称查询非当前菜单主键
     *
     * @param menuId           当前菜单主键
     * @param businessSystemId 业务系统主键
     * @param parentId         父菜单主键
     * @param menuName         菜单名称
     * @return
     * @author LiCongLu
     * @date 2020-03-18 15:29
     */
    @Select(" select id from business_system_menu where id != IFNULL(#{menuId},0) and business_system_id = #{businessSystemId} and parent_id = #{parentId} and menu_name = #{menuName} and deleted = 0 limit 1 ")
    @ResultType(Integer.class)
    Integer getSystemMenuIdByMenuName(@Param("menuId") Integer menuId, @Param("businessSystemId") Integer businessSystemId, @Param("parentId") Integer parentId, @Param("menuName") String menuName);
}
